# _*_ coding:UTF-8 _*_
"""
__author__ = 'shede333'
"""


import shell_command


def _print_output(command, *info_list):
    print "*"*15, "git", "*"*15
    print "command: "
    print "\t", command
    print "output:"
    print "\n".join(["\t" + tmp_info for tmp_info in info_list])
    print "*"*30


def _run_command(command, is_check, print_log):
    run_code, run_output = shell_command.call(command, is_check)
    if print_log:
        _print_output(command, run_output)
    return run_code, run_output


def clone(url, des_dir_path, is_check=False, print_log=True):
    command = "git clone {0} --recurse {1}".format(url, des_dir_path)
    return _run_command(command, is_check, print_log)


def pull(dir_path, print_log=True):
    command = "cd {0}; git pull".format(dir_path)
    return _run_command(command, print_log=print_log)


def status(dir_path, print_log=True):
    command = "cd '{0}'; git status".format(dir_path)
    return _run_command(command, print_log=print_log)


def work_space_is_clean(dir_path):
    out_put = status(dir_path)[1]
    if "nothing to commit, working directory clean" in out_put:
        return True
    else:
        return False
